import torch.nn as nn


class SEBlock(nn.Module):
    def __init__(self, channel, reduction=6, *args, **kwargs):
        super().__init__()
        self.avg_pool = nn.AdaptiveAvgPool2d(1)
        self.fc = nn.Sequential(
            nn.Linear(channel, channel // reduction),  # 降维
            nn.ReLU(),
            nn.Linear(channel // reduction, channel),  # 升维
            nn.Sigmoid()  # 归一化为权重
        )

    def forward(self, x):
        b, c, _, _ = x.size()
        y = self.avg_pool(x).view(b, c)
        y = self.fc(y).view(b, c, 1, 1)
        return x * y
